const Router = require('@koa/router')
// const { User } = require('../databases/models/user')
const { User } = require('../databases/index')


const userRouter = new Router({   //实例化用户相关的子路由对象
    prefix: '/user' //设置路由前缀
});

userRouter.get('/', async (ctx, next) => {
    const users = await User.findAll();
    ctx.body = {
        code: 200,
        message: 'User home page',
        data: users,
    };
});
userRouter.post('/add', async (ctx, next) => {
    console.log('请求体数据：', ctx.request.body); // 打印请求体
    const { userName, password, email } = ctx.request.body;
    const currentUser = await User.create({
        userName,
        password,
        email,
        
    });
    ctx.body = {
        message: 'Add user',
        data: currentUser,
    }

});



module.exports = userRouter;
